package com.agriculture.monitor.service.impl;

import com.agriculture.monitor.dto.DevicePage;
import com.agriculture.monitor.dto.PositionPage;
import com.agriculture.monitor.entity.Device;
import com.agriculture.monitor.entity.Position;
import com.agriculture.monitor.entity.User;
import com.agriculture.monitor.mapper.DeviceMapper;
import com.agriculture.monitor.service.IDeviceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-03-16
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements IDeviceService {

    @Override
    @Transactional
    public Device saveData(Device device) {
        if (device.getId() == null) {
            baseMapper.insert(device);
        } else {
            baseMapper.updateById(device);
        }

        return device;
    }

    @Override
    public Page<Device> listPage(DevicePage basePage) {
        Page<Device> page = new Page(basePage.getPageCurrent(), basePage.getPageSize());
        return baseMapper.findPage(page, basePage);
    }
}
